import { http } from './request'
//收藏文章
export const likeArticle = (id) => {
  return new Promise((reslove, reject) => {
    http({
      url: '/subject/favorite?subjectId=' + id,
      method: 'post',
    })
      .then((res) => {
        reslove(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

//取消收藏
export const delectLike = (id) => {
  return new Promise((reslove, reject) => {
    http({
      url: '/subject/favorite?subjectIds=' + id,
      method: 'delete',
    })
      .then((res) => {
        reslove(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

// 检索该文章是否有收藏过
export const inspectHasColl = (id) => {
  return new Promise((reslove, reject) => {
    http({
      url: '/subject/favorite/joined?subjectId=' + id,
      method: 'get',
    })
      .then((res) => {
        reslove(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

// 用户发表评论
export const userTalk = (resourceId, intro) => {
  return new Promise((reslove, reject) => {
    http(
      {
        url: '/subject/comment',
        method: 'post',
      },
      { resourceId, intro }
    )
      .then((res) => {
        reslove(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

//用户回复评论
export const replyMsg = (atCommentId, intro) => {
  return new Promise((relove, reject) => {
    http(
      {
        url: '/subject/comment/reply',
        method: 'post',
      },
      { atCommentId, intro }
    )
      .then((res) => {
        relove(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

//获取用户的新闻列表评论
export const comList = (index, size) => {
  return new Promise((reslove, reject) => {
    http(
      {
        url: '/user/subject/comment',
        method: 'get',
      },
      { index, size }
    )
      .then((res) => {
        reslove(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

//删除用户自己的评论
export const deletCom = (id) => {
  return new Promise((reslove, reject) => {
    http({
      url: '/subject/comment?id=' + id,
      method: 'DELETE',
    })
      .then((res) => {
        reslove(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

//获取用户的浏览历史记录
export const userHistory = (index, size) => {
  return new Promise((resolve, reject) => {
    http(
      {
        method: 'get',
        url: '/user/subject/visit',
      },
      {
        index,
        size,
      }
    )
      .then((res) => {
        resolve(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

//获取图文的数据
export const photoArticle = (id) => {
  return new Promise((resolve, reject) => {
    http(
      {
        url: '/news/' + id,
        method: 'get',
      },
      null,
      true
    )
      .then((res) => {
        resolve(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

//获取视频播放地址
export const getVideoUrl = (videoId) => {
  return new Promise((resolve, reject) => {
    http(
      {
        url: '/vod/video/play/url?videoId=' + videoId,
        method: 'get',
      },
      null,
      true
    )
      .then((res) => {
        resolve(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

//获取推荐的新闻列表   新闻id
export const recommendNew = (subjectId) => {
  return new Promise((resolve, reject) => {
    http(
      {
        url: '/news/like?subjectId=' + subjectId,
        method: 'get',
      },
      null,
      true
    )
      .then((res) => {
        resolve(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

//获取详情页的评论列表数据

export const getCommentlistData = (index, size, subjectId) => {
  return new Promise((resolve, reject) => {
    http(
      {
        url: '/subject/comment',
        method: 'get',
      },
      { index, size, subjectId },
      true
    )
      .then((res) => {
        resolve(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

//搜索里面的热门分类
export const hotClassify = () => {
  return new Promise((resolve, reject) => {
    http(
      {
        url: '/category/hots',
        method: 'get',
      },
      null,
      true
    )
      .then((res) => {
        resolve(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

//获取首页的区块信息 专题 排行等等
export const getBlockInfo = () => {
  return new Promise((resolve, reject) => {
    http(
      {
        url: '/index/block/dynamic',
        method: 'get',
      },
      null,
      true
    )
      .then((res) => {
        resolve(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

//获取首页的数据
export const indexInfo = (lastCursor) => {
  return new Promise((resolve, reject) => {
    http(
      {
        url: '/index',
        method: 'get',
      },
      { lastCursor },
      true
    )
      .then((res) => {
        resolve(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

//获取专题页数据
export const getSpacialData = (id) => {
  return http(
    {
      url: '/topic/' + id,
      method: 'get',
    },
    null,
    true
  )
}

//直播类接口================================================

//获取直播地址
export const getLiveUrl = (id) => {
  return new Promise((resolve, reject) => {
    http(
      {
        url: '/live/stream/playurl?id=' + id,
        method: 'get',
      },
      null,
      true
    )
      .then((res) => {
        resolve(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

//获取直播间信息

export const getLiveInfo = (id) => {
  return new Promise((resolve, reject) => {
    http(
      {
        url: `/live/${id}`,
        method: 'get',
      },
      null,
      true
    )
      .then((res) => {
        resolve(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

//直播类接口-----------------------------------------------

//检测用户信息
export const detectionToken = () => {
  return new Promise((reslove, reject) => {
    http(
      {
        urlType: true,
        url: '/passport/account',
        method: 'get',
      },
      null,
      true
    ).then((res) => {
      reslove(res)
    })
  })
}

//获取评论的详情
export const getPersonChart = (commentId, index, size) => {
  return new Promise((reslove, reject) => {
    http(
      {
        url: '/subject/comment/reply',
        method: 'get',
      },
      { commentId, index, size },
      true
    )
      .then((res) => {
        reslove(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}



//获取回复的列表的上一级数据详情
export const getReplaydetail=(id)=>{
  return new Promise((reslove,reject)=>{
    http({
      url:"/subject/comment/"+id,
      method:"get"
    },null,true).then(res=>{
      reslove(res)
    }).catch(err=>{
      reject(err)
    })
  })
}

//收藏专题
export const collectSpacial=(id)=>{
  return new Promise((resolve,reject)=>{
    http({
      url:"/topic/content/favorite?id="+id,
      method:'post'
    }).then(res=>{
        resolve(res)
    }).catch((err)=>{
      reject(err)
    })
  })
}

//取消滑动图片那里的收藏状态
export const cancelSpacial=(id)=>{
  return new Promise((resolve,reject)=>{
    http({
      url:"/topic/content/favorite/cancel?id="+id,
      method:"post",
    }).then(res=>{
      resolve(res)
    }).catch(err=>{
      reject(err)
    })
  })
}


//查询是否有收藏过
export const spacialState=(id)=>{
  return new Promise((resolve,reject)=>{
    http({
      url:"/topic/content/favorite?id="+id,
      method:"get"
    },null,true).then(res=>{
      resolve(res)
    }).catch(err=>{
      reject(err)
    })
  })
}
